import cv2
import numpy as np
import time


def read_bin_image(path):
    # resource = cv2.imread('../resource/1.png', cv2.IMREAD_UNCHANGED)
    img = cv2.imread(path, cv2.IMREAD_UNCHANGED)
    b, g, r, a = cv2.split(img)
    a = cv2.copyMakeBorder(a, 50, 50, 50, 50, cv2.BORDER_CONSTANT, value=[0])
    rows, cols = a.shape
    M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 0, 1)
    dst = cv2.warpAffine(a, M, (cols, rows))
    ret, thresh1 = cv2.threshold(dst, 127, 255, cv2.THRESH_BINARY)
    print(thresh1.shape)
    print(thresh1[49][49])
    return thresh1



while (1):
    cv2.imshow('resource', read_bin_image('../resource/pipeA.png'))

    if cv2.waitKey(1) & 0xFF == 27:
        break

cv2.destroyAllWindows()
